package thn.glf.org.personalfinancial.model;

import java.text.DecimalFormat;
import java.util.ArrayList;

import thn.glf.org.personalfinancial.R;
import thn.glf.org.personalfinancial.objData.FinancialDay;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class FinancialDayAdapter extends BaseExpandableListAdapter {
	private Context context;
	private ArrayList<FinancialDay> lstFinancialDay;

	public FinancialDayAdapter(Context mcontext, ArrayList<FinancialDay> lst) {
		this.context = mcontext;
		this.lstFinancialDay=lst;
		if(this.lstFinancialDay==null){
			this.lstFinancialDay=new ArrayList<FinancialDay>();
		}
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return this.lstFinancialDay.get(childPosition);
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		FinancialDay data=lstFinancialDay.get(groupPosition);
		if (convertView == null) {
			   LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			   convertView = infalInflater.inflate(R.layout.moneyofdaylist_item, null);
			  }
		TextView sp=(TextView)convertView.findViewById(R.id.sp);
		sp.setText(data.getProductName());
		TextView money=(TextView)convertView.findViewById(R.id.money);
		 DecimalFormat df=new DecimalFormat();
		money.setText(df.format( data.getPriceMoney()).toString());
		TextView times=(TextView)convertView.findViewById(R.id.times);
		times.setText(data.getTimes().substring(0,2)+":"+data.getTimes().substring(2,4));
		TextView date=(TextView)convertView.findViewById(R.id.date);
		date.setText(data.getDays().substring(0,4)+"/"+data.getDays().substring(4,6)+"/"+data.getDays().substring(6,8));
		TextView place=(TextView)convertView.findViewById(R.id.place);
		place.setText(data.getPlace());
		TextView note=(TextView)convertView.findViewById(R.id.note);
		note.setText(data.getNote());
		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return lstFinancialDay.get(groupPosition);
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return lstFinancialDay.size();
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			   LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			   convertView = inf.inflate(R.layout.group_heading_days, null);
			  }
			   
			  TextView heading = (TextView) convertView.findViewById(R.id.heading);
			  heading.setText(String.format("%04d",this.lstFinancialDay.get(groupPosition).getDayID()));			  			  
			  return convertView;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return false;
	}

	

}
